package com.tshopping.controller;

import com.tshopping.bean.DataModel;
import com.tshopping.bean.Page;
import com.tshopping.service.CartService;
import com.tshopping.util.ResponseData;
import com.tshopping.util.TimeProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 * @name: CartController
 * @description: 购物车页面控制器
 * @author: Jackeys
 * @date: 2021-01-27 21:06
 */
@RestController
@RequestMapping("/CartController")
@CrossOrigin
public class CartController {

    @Autowired
    private CartService cartService;

    @PostMapping(value = "/getCartGoods")
    /**
     * @description 获取购物车商品
     * @Param: user
     * @Param: currentPage
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-28 09:44
     */
    public ResponseData getCartGoods(int user, int currentPage){
        return cartService.getCartsByUser(user,currentPage);
    }

    @PostMapping(value = "/addCart")
    /**
     * @description 加入购车
     * @Param: user
     * @Param: goods
     * @Param: parameter
     * @Param: number
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-28 09:49
     */
    public ResponseData addCart(int user,int goods,int parameter,int number) throws ParseException {
        return cartService.addCart(user,goods,parameter,number, TimeProvider.getTime());
    }

    @PostMapping(value = "/deleteCart")
    /**
     * @description 删除购物车商品
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-28 09:51
     */
    public ResponseData deleteCart(int id){
        return cartService.deleteCartById(id);
    }

    @PostMapping(value = "updateCart")
    /**
     * @description 修改购物车
     * @Param: number
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-28 09:53
     */
    public ResponseData updateCart(int number,int id){
        return cartService.updateCartByNumber(number,id);
    }

}
